package com.sale.system.dubbo;

import com.sale.system.api.RemoteWorkbenchMessageService;
import com.sale.system.api.domain.SysWorkbenchMessageResult;
import com.sale.system.api.domain.dto.SysTheAlarmDto;
import com.sale.system.api.domain.vo.SysWorkbenchAuditAgentDubboVo;
import com.sale.system.api.domain.vo.SysWorkbenchMessageVo;
import com.sale.system.domain.SysTheAlarm;
import com.sale.system.domain.SysWorkbenchMessage;
import com.sale.system.service.SysWorkbenchAuditAgentService;
import com.sale.system.service.SysWorkbenchMessageService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 消息提醒服务
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteWorkbenchMessageServiceImpl implements RemoteWorkbenchMessageService {

    @Resource
    SysWorkbenchMessageService sysWorkbenchMessageService;

    @Resource
    SysWorkbenchAuditAgentService sysWorkbenchAuditAgentService;

    /**
     * 新增
     *
     * @param list
     * @return
     */
    @Override
    public boolean insertWork(List<SysWorkbenchMessageVo> list) {
        List<com.sale.system.domain.vo.SysWorkbenchMessageVo> objects = new ArrayList<>();
        for (SysWorkbenchMessageVo entity : list) {
            com.sale.system.domain.vo.SysWorkbenchMessageVo sysWorkbenchMessageVo = new com.sale.system.domain.vo.SysWorkbenchMessageVo();
            BeanUtils.copyProperties(entity, sysWorkbenchMessageVo);
            objects.add(sysWorkbenchMessageVo);
        }
        return sysWorkbenchMessageService.insertWork(objects);
    }

    /**
     * 批量新增审核待办
     *
     * @param sysWorkbenchAuditAgentDubboVo
     * @return
     */
    @Override
    public boolean insertAuditAgent(SysWorkbenchAuditAgentDubboVo sysWorkbenchAuditAgentDubboVo) {
        com.sale.system.domain.vo.SysWorkbenchAuditAgentVo sysWorkbenchAuditAgentVo1 = new com.sale.system.domain.vo.SysWorkbenchAuditAgentVo();
        BeanUtils.copyProperties(sysWorkbenchAuditAgentDubboVo, sysWorkbenchAuditAgentVo1);
        return sysWorkbenchAuditAgentService.insertAuditAgent(sysWorkbenchAuditAgentVo1);
    }

    /**
     * 修改审核代办状态
     *
     * @param status
     * @param receiptNumber
     * @param modelName
     * @return
     */
    @Override
    public boolean updateStatus(int status, String receiptNumber, String modelName) {
        return sysWorkbenchAuditAgentService.updateStatus(status, receiptNumber, modelName);
    }

    /**
     * 删除审核代办
     *
     * @param receiptNumber
     * @param modelName
     * @return
     */
    @Override
    public boolean deleteDoc(String receiptNumber, String modelName) {
        return sysWorkbenchAuditAgentService.deleteDoc(receiptNumber, modelName);
    }

    /**
     * 查询最近一次库存量和物料编码的数据
     */
    @Override
    public List<SysWorkbenchMessageResult> getInfo(String type) {
        List<SysWorkbenchMessage> info = sysWorkbenchMessageService.getInfo(type);
        List<SysWorkbenchMessageResult> results = new ArrayList<>();
        for (SysWorkbenchMessage entity : info) {
            SysWorkbenchMessageResult sysWorkbenchMessageResult = new SysWorkbenchMessageResult();
            BeanUtils.copyProperties(entity, sysWorkbenchMessageResult);
            results.add(sysWorkbenchMessageResult);
        }
        return results;
    }

    /**
     * 查询告警信息
     */
    @Override
    public SysTheAlarmDto getAlarm(String materialCode, String type) {
        SysTheAlarm alarm = sysWorkbenchMessageService.getAlarm(materialCode, type);
        SysTheAlarmDto sysTheAlarmDto = new SysTheAlarmDto();
        if (alarm != null) {
            BeanUtils.copyProperties(alarm, sysTheAlarmDto);
        }
        return sysTheAlarmDto;
    }
}
